
import functools

#自定义过滤器
from flask import current_app
from flask import g
from flask import session

from info1.models import User


def index_class(index):
    if index==1:
        return 'first'
    elif index==2:
        return 'send'
    elif index==3:
        return 'third'
    else:
        return ''



#自定义装饰器
def login_required(f):
    @functools.wraps(f)
    def wrapper(*args,**kwargs):
        user_id = session.get('user_id')
        user = None
        #判断user_id
        if user_id:
            try:
                user = User.query.filter_by(id=user_id).first()
            except Exception as e :
                current_app.logger.error(e)
                #使用g对象储存user
        g.user = user
        return f(*args,**kwargs)
    return wrapper

















